﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skynet.WebAdministracion.Views.ExamViewer;
using Microsoft.Practices.Unity;

namespace Skynet.WebSite.Evaluation
{
    public partial class ExamViewer : Infrastructure.Web.Views.Page, IExamViewerView
    {
        private ExamViewerPresenter _Presenter;
        [Dependency]
        public ExamViewerPresenter Presenter
        {
            get { return _Presenter; }
            set
            {
                _Presenter = value;
                this._Presenter.View = this;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                this.Presenter.OnViewInitialized();
            else
                this.Presenter.OnViewLoaded();            
        }

        public Control QuestionControl
        {
            get
            {
                return pnQuestion.Controls[0];
            }
            set
            {
                pnQuestion.Controls.Add(value);
            }
        }

        public List<Control> AlternativesControls
        {
            get
            {
                List<Control> result = new List<Control>();
                foreach (var item in   this.pnAlternatives.Controls)
                {
                    if ( item is Control)
                    result.Add(item as Control);                    
                }
                return result;
            }
            set
            {
                foreach (var item in value)
                {
                    this.pnAlternatives.Controls.Add(item);                   
                }
            }
        }

        public int CurrentPosition
        {
            set { this.lblPosition.Text = value.ToString(); }
        }

        public int TotalQuestions
        {
            set { this.lblTotal.Text = value.ToString(); }
        }


        protected void lbNext_Click(object sender, EventArgs e)
        {
            this.Presenter.Next();
        }


        public bool Review
        {
            get
            {
                return this.cbReview.Checked;
            }
            set
            {
                this.cbReview.Checked = value;
            }
        }

        protected void lbPrevius_Click(object sender, EventArgs e)
        {
            this.Presenter.Previus();
        }

        protected void lbReview_Click(object sender, EventArgs e)
        {
            this.Presenter.ShowReview();
        }


        public DateTime EndExam
        {            
            set
            {
                this.lblTime.Text = value.ToLongTimeString();
            }
        }
    }
}